<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <th:script src="../js/jquery-1.8.3.min.js"></th:script>
</head>
<body>
    <h1>test</h1>

    <script>
        $(function(){
            alert(123);
            $.ajax({
                type: 'get',
                url: '/test2',
                headers: {token: getCookie("token")},
                success: function (data) {
                    console.log(data)
                }
            })
        })
        function getCookie(cookieName) {
            //获取当前所有cookie
            var strCookies = document.cookie;

            //截取变成cookie数组
            var array = strCookies.split(';');

            //循环每个cookie
            for (var i = 0; i < array.length; i++) {
                //将cookie截取成两部分
                var item = array[i].split("=");
                //判断cookie的name 是否相等
                if (item[0] == cookieName) {
                    return item[1];
                }
            }
            return null;
        }
    </script>
</body>
</html>